import django_filters

from apps.HttpTestcase.models import TestcaseReports


class Test_reportsFilter(django_filters.rest_framework.FilterSet):
    """
    过滤
    """
    # iexact表示精确匹配, 并且忽略大小写
    # icontains表示模糊查询（包含），并且忽略大小写
    # exact表示精确匹配
    # testsuite_reports = django_filters.CharFilter(method='testsuite_reports')
    testsuite_id = django_filters.CharFilter(field_name='testsuite_id')
    version = django_filters.CharFilter(field_name='version', lookup_expr='exact')
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    url = django_filters.CharFilter(field_name='url', lookup_expr='icontains')
    testcase_name = django_filters.CharFilter(field_name='testcase_name',lookup_expr='icontains')
    project = django_filters.CharFilter(field_name='project',lookup_expr='exact')
    api = django_filters.CharFilter(field_name='api',lookup_expr='exact')
    status = django_filters.CharFilter(field_name='status',lookup_expr='exact')

    def testsuite_reports_filter(self, queryset, name, value):
        return queryset.filter(testsuite_result=value)

    # def testsuite_id_filter(self, queryset, name, value):
    #     return queryset.filter(testsuite_reports_id=value.values('testsuite_reports__testsuite__name'))

    class Meta:
        model = TestcaseReports
        fields = ['version']
